//
//  BFShOrderHeaderView.m
//  BeautyFood
//
//  Created by apple on 2020/5/5.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "BFShOrderFooterView.h"
@interface BFShOrderFooterView()
@property(nonatomic, strong) STLabel                     *money_lable;/**<  */
@property(nonatomic, strong) UIView                     *white_view;/**<  */
@property(nonatomic, strong) NSMutableArray                     *button_array;/**<  */
@end
@implementation BFShOrderFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithReuseIdentifier:reuseIdentifier]) {
        [self stoneobs_ui_configSubView];
    }
    return self;
}
+ (CGFloat)stoneobs_ui_cell_height{
    return 50 + 35 ;
}
#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = UIColor.clearColor;
    CGFloat cornerRadius = 8;
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, -cornerRadius, STONEOBS_UI_UISCREEN_WIDTH - 0, self.class.stoneobs_ui_cell_height + 0)];
    whiteView.backgroundColor = UIColor.whiteColor;
    whiteView.layer.cornerRadius = cornerRadius;
    whiteView.clipsToBounds = YES;
    [self addSubview:whiteView];
    self.white_view = whiteView;
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(12, 10, 200, 20)
                                                                text:@"订单时间：2020-01-07 16:03"
                                                           textColor:FlatRed
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentRight];
        [whiteView addSubview:stoneobs_ui_label];
        self.money_lable  = stoneobs_ui_label;
        stoneobs_ui_label.right = self.white_view.width - 12;
    });
    
    
    
    
}
- (void)clear_all_menu_button{
    [self.button_array makeObjectsPerformSelector:@selector(removeFromSuperview)];
}
+ (NSArray*)arrayFormModel:(BFShOrderModel*)model{
    NSMutableArray * array = NSMutableArray.new;
    //                     -1 => '已取消',
    //                    0  => '待分拣' ,
    //                    1  => '分拣中' ,
    //                    2  => '分拣完成' ,
    //                    3  =>'总仓出库',
    //                    4  => '到达分仓' ,
    //                    5  => '分仓已发出',
    //                    6  => '已送达',
    //                    7  => '已完成',
    //                    8  => '售后中',
    //                    9  =>'售后处理完成'
    if (model.status.intValue == 0) {
        if (model.status.intValue == 0 ) {
            [array addObject:@"去支付"];
        }
         [array addObject:@"取消订单"];
        
        
    }

    if (model.status.intValue == 1) {
        [array addObject:@"取消订单"];
    }
    if (model.status.intValue == 2) {
       [array addObject:@"确认收货"];
        [array addObject:@"查看物流"];
    }
    if (model.status.intValue == 3) {
       [array addObject:@"去评价"];
        [array addObject:@"查看物流"];
        [array addObject:@"删除订单"];
        [array addObject:@"申请售后"];
    }
    if (model.status.intValue == 6) {
        [array addObject:@"查看售后"];
    }
    
    return array;
}
- (void)refresh_footer{
    [self.button_array makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.button_array = NSMutableArray.new;
    NSArray * array = [self.class arrayFormModel:self.model];
    for (NSString * name in array) {
        [self add_button_title:name];
    }
    
}
- (void)add_button_title:(NSString*)title{
    
    STButton * lastButton = self.button_array.lastObject;
    
    STButton * addButton = [BFShOrderFooterView buttonFormTitle:title];
    addButton.right = lastButton.left - 5;
    if (!lastButton) {
        addButton.right = self.white_view.width - 12;
    }
    addButton.top = self.money_lable.bottom+10;
    [self.white_view addSubview:addButton];
    [self.button_array addObject:addButton];
    __weak typeof(self) weakSelf =  self;
    [addButton setClicAction:^(UIButton *sender) {
        if (weakSelf.didSlectedMenuTitle) {
            weakSelf.didSlectedMenuTitle(title);
        }
    }];
    
}
+ (STButton*)buttonFormTitle:(NSString*)title{
    NSInteger font_num = 12;
    STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 0, font_num, font_num*2)
                                                              title:title
                                                         titleColor:WH_UICOLOR_FROM_RGBA(0x606060)
                                                          titleFont:font_num
                                                       cornerRadius:font_num
                                                    backgroundColor:nil
                                                    backgroundImage:nil
                                                              image:nil];
    stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [stoneobs_ui_button stbw_setBorderWith:0.5 borderColor:WH_UICOLOR_FROM_RGBA(0x606060) cornerRadius:font_num];
    stoneobs_ui_button.centerY = self.stoneobs_ui_cell_height / 2;
    if ( [title isEqualToString:@"查看售后"] ) {
        [stoneobs_ui_button stbw_setBorderWith:0.5 borderColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR cornerRadius:font_num];
        [stoneobs_ui_button setTitleColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR forState:UIControlStateNormal];
    }
    if ([title isEqualToString:@"去支付"] || [title isEqualToString:@"去评价"] ) {
        [stoneobs_ui_button stbw_setBorderWith:0.5 borderColor:UIColor.whiteColor cornerRadius:font_num];
        [stoneobs_ui_button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [TMUtils stoneobs_fun_makeViewToThemeGrdualColor:stoneobs_ui_button];
    }
    
    CGFloat witdh = [title stoneobs_fun_st_widthWithheight:font_num font:font_num];
    witdh = witdh + font_num;
    stoneobs_ui_button.width = witdh;
    if ([title isEqualToString:@"去支付"] || [title isEqualToString:@"去评价"] ) {
        [TMUtils stoneobs_fun_makeViewToThemeGrdualColor:stoneobs_ui_button];
    }
    return stoneobs_ui_button;
    
}
- (void)setModel:(BFShOrderModel *)model{
    _model = model;
    [self refresh_footer];
    
    self.money_lable.text = [NSString stringWithFormat:@"￥%.2f",model.total_price.floatValue];
    self.money_lable.attributedText = [self.money_lable.text stoneobs_fun_st_convertAttributeStringWithKeyWord:@"￥" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]}];
    
    
    
}

@end
